package cn.com.mall.gateway.config;

import cn.com.mall.common.utils.R;
import com.alibaba.csp.sentinel.adapter.gateway.sc.callback.GatewayCallbackManager;
import com.alibaba.fastjson.JSON;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

@Configuration
public class SentinelGateWay {

    public SentinelGateWay(){
        GatewayCallbackManager.setBlockHandler((serverWebExchange,throwable)->{
            R r = R.error(502, "网络流控限制");
            String s = JSON.toJSONString(r);
            Mono<ServerResponse> body = ServerResponse.ok().body(Mono.just(s), String.class);
            return body;
        });
    }
}
